package cn.hg.jfsa.manage.directive;

import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.SqlPara;
import com.jfinal.plugin.ehcache.CacheKit;
import com.jfinal.plugin.ehcache.IDataLoader;
import com.jfinal.template.Env;
import com.jfinal.template.io.Writer;
import com.jfinal.template.stat.Scope;

import cn.hg.base.jfinal.directive.annotation.JfsaDirective;
import cn.hg.jfsa.common.directive.BaseDirective;
import cn.hg.jfsa.model.JfsaAdmin;

@JfsaDirective ("adminList")
public class AdminListDirective extends BaseDirective {

	@Override
	public boolean hasEnd () {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * @see cn.hg.base.jfinal.directive.BaseDirective#onRender(com.jfinal.template.Env, com.jfinal.template.stat.Scope,
	 * com.jfinal.template.io.Writer)
	 */
	@Override
	public void onRender (Env env, Scope scope, Writer writer) {
		Map<String, Object> paraMap = this.getAssignedParaMap(scope);
		List<JfsaAdmin> list = CacheKit.get("jfsaAdmin", "adminList_" + paraMap.toString(), new IDataLoader() {

			@Override
			public Object load () {
				SqlPara sqlPara = JfsaAdmin.DAO.getSqlPara("system.findAdmin", paraMap);
				return JfsaAdmin.DAO.find(sqlPara);
			}

		});
		scope.setLocal(this.getPara("var", scope, "adminList"), list);
		this.renderBody(env, scope, writer);
	}

}
